import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../../providers/provider_container.dart';
import '../intent/splash_state.dart';
import '../model/splash_viewmodel.dart';

class SplashPage extends ConsumerStatefulWidget {
  @override
  ConsumerState<ConsumerStatefulWidget> createState() {
    return _SplashPageState();
  }
}

class _SplashPageState extends ConsumerState<SplashPage> {
  // 使用 getter 来获取 ViewModel
  SplashViewModel get viewModel => ref.read(splashViewModelProvider.notifier);

  @override
  void initState() {
    super.initState();
    // 在页面初始化时执行网络请求
    WidgetsBinding.instance.addPostFrameCallback((_) {
      viewModel.initData();
    });
  }

  // model‌：管理应用状态；
  // view‌：负责UI渲染和用户交互；
  // intent‌：表示用户操作或数据变化意图，触发状态更新
  @override
  Widget build(BuildContext context) {
    final SplashState state = ref.watch(splashViewModelProvider);
    return Scaffold(
      body: Container(
        width: double.infinity,
        height: double.infinity,
        child: Center(child: Text(state.appState)),
      ),
    );
  }
}